package org.usmile.algorithms.huawei.acm;

import java.util.Arrays;
import java.util.Comparator;
import java.util.PriorityQueue;
import java.util.Scanner;

// https://fcqian.blog.csdn.net/article/details/128192516
public class _最大化控制资源成本 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[][] ranges = new int[n][3];
        for (int i = 0; i < n; i++) {
            ranges[i][0] = sc.nextInt();
            ranges[i][1] = sc.nextInt();
            ranges[i][2] = sc.nextInt();
        }

        System.out.println(getResult(ranges));
    }

    public static int getResult(int[][] ranges) {
        Arrays.sort(ranges, Comparator.comparingInt(a -> a[0]));

        PriorityQueue<int[]> heap = new PriorityQueue<>();
        int maxParallelism = 0;
        int currParallelism = 0;
        for (int[] range : ranges) {
            int startTime = range[0];
            int endTime = range[1];
            int parallelism = range[2];
            while (heap.size() > 0) {
                int[] task = heap.peek();
                if (task[0] <= startTime) {
                    int[] poll = heap.poll();
                    currParallelism -= poll[1];
                } else {
                    break;
                }
            }
            heap.offer(new int[]{endTime, parallelism});
            currParallelism += parallelism;
            maxParallelism = Math.max(maxParallelism, currParallelism);
        }
        return maxParallelism;
    }
}
